<?php

namespace common\models\SystemConfig;

use Yii;
use yii\helpers\ArrayHelper;

/**
 * This is the model class for table "system_config".
 *
 * @property int $id
 * @property string $key key
 * @property string $name name
 * @property string $value value
 * @property int $created_at
 * @property int $updated_at
 */
class SystemConfig extends \common\models\BaseModel
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'system_config';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['value'], 'string'],
            [['created_at', 'updated_at'], 'integer'],
            [['key', 'name'], 'string', 'max' => 50],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app', 'ID'),
            'key' => Yii::t('app', 'key'),
            'name' => Yii::t('app', 'name'),
            'value' => Yii::t('app', 'value'),
            'created_at' => Yii::t('app', 'Created At'),
            'updated_at' => Yii::t('app', 'Updated At'),
        ];
    }

    public static function getValueByKey($key)
    {
       $config = self::findOne(['key' => $key]);
       return $config ? $config->value : '';
    }
}
